import Mock from "mockjs";
import "@/mock/extend";
import { parseUrlParams } from "@/utils/request";

const source = Mock.mock({
  "list|50-80": [
    {
      "key|+1": 0,
      version: /2024年(?:1[0-2]|[1-9])月/,
      "taskType|1": ["评审类", "设备类", "研发类", "专业小组类", "其他类"],
      "phase|1": ["方案评审", "迁移改造", "切流", "应用下线", "退库"],
      "granularity|1": ["按部门", "按场景", "按程序"],
      "finishContent|1": ["慢SQL治理", "批量改造"],
      "acceptanceDepartment|1": ["系统二部", "应用支持三部", "应用支持一部"],
      "acceptor|1": ["张三", "李四", "王五"],
      "result|1": ["已完成", "未完成"],
      "risk|1": ["", "暂无风险", "需要延期"],
      "requireItems|1": [
        "ADLM高斯数据库5月版本适配改造",
        "ADLM高斯数据库6月版本适配改造",
        "ADLM高斯数据库7月版本适配改造",
      ],
      "requireNo|0-50": 5,
      "requireName|1": ["需求名1", "需求名2"],
      "requireState|1": ["正在进行", "需求延期", "已删除"],
      "busType|1": ["主机上云", "迁移改造", "业务开发"],
      "funcType|1": ["新增", "删除", "修改", "查询"],
      "sceneType|1": ["迁移转型", "内容改造"],
      "resourcePlanNo|0-50": 5,
    },
  ],
});

const appSource = Mock.mock({
  "list|8-12": [
    {
      "key|+1": 0,
      "nickName|1": ["F-ACIS", "F-CCPS", "F-CEBS", "F-ECIS"],
      "appName": "这是应用名称",
      "contact|1": ["张三", "李四", "王五", "燕六"],
      "depart|1": ["系统二部", "应用支持三部", "应用支持一部"],
      "tag|1": ["2024年信创","2023年信创","2025年信创"]
    },
  ],
});

Mock.mock(
  RegExp(`${process.env.VUE_APP_API_BASE_URL}/planList` + ".*"),
  "get",
  ({ url }) => {
    const params = parseUrlParams(decodeURI(url));
    // let {page, pageSize} = params
    // page = eval(page) - 1 || 0
    // pageSize = eval(pageSize) || 10

    // delete params.page
    // delete params.pageSize

    let result = source.list.filter((item) => {
      for (let [key, value] of Object.entries(params)) {
        if (item[key] !== value) {
          return false;
        }
      }
      return true;
    });
    const total = result.length;
    // if ((page) * pageSize > total) {
    //   result = []
    // } else {
    //   result = result.slice(page * pageSize, (page + 1) * pageSize)
    // }

    return {
      code: 0,
      message: "success",
      data: {
        // page: page + 1,
        // pageSize,
        total: total,
        list: result,
      },
    };
  }
);

Mock.mock(
  RegExp(`${process.env.VUE_APP_API_BASE_URL}/appList` + ".*"),
  "get",
  ({ url }) => {
    const params = parseUrlParams(decodeURI(url));

    let result = appSource.list.filter((item) => {
      for (let [key, value] of Object.entries(params)) {
        if (item[key] !== value) {
          return false;
        }
      }
      return true;
    });
    const total = result.length;

    return {
      code: 0,
      message: "success",
      data: {
        total: total,
        list: result,
      },
    };
  }
);
